// 注册路由的业务逻辑处理
const express = require("express");
const router = express.Router();
const usertable = require("../../database/userinfo")

router.post("/", async (req, res) => {
    let { username, password } = req.body;
    let userDoc = await usertable.findOne({ username })
    if (userDoc) {
        res.send({
            code: 2,
            message: "用户已存在"
        })
    } else {
        await usertable.create({ username, password, photo: "/images/default/" + Math.floor(Math.random() * 6) + ".jpg" });
        res.send({
            code: 0,
            message: "注册用户成功"
        })
    }

});

module.exports = router;




